package client;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.CharacterControl;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;



public class PhysicsController 
{
    private static BulletAppState bulletAppState;
    
    public static void initPhysics(SimpleApplication app)
    {
        bulletAppState = new BulletAppState();
        bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
        app.getStateManager().attach(bulletAppState);
    }
    
    public static void addChild(Node node)
    {
        bulletAppState.getPhysicsSpace().addAll(node);
    }
    
    public static void addChild(Spatial node)
    {
        bulletAppState.getPhysicsSpace().addAll(node);
    }

    public static void addChild(Geometry geom) 
    {
        bulletAppState.getPhysicsSpace().addAll(geom);
    }
    
    public static void addChild(CharacterControl unit) 
    {
        bulletAppState.getPhysicsSpace().add(unit);
    }
    
    public static void addChild(RigidBodyControl cont)
    {
        bulletAppState.getPhysicsSpace().add(cont);
    }
    
    /*
    soft_remove_child:
    removes a child from the physics space, but not the root node
    */
    public static void softRemoveChild(Node node)
    {
        if (node != null) 
        {
            bulletAppState.getPhysicsSpace().remove(node);
            //Main.lights.redoShadows();
        }
    }
    
    /*
    kill_child:
    removes a child from the physics space and the root node
    */
    public static void killChild(Node node)
    {
        if (node != null) 
        {
            node.detachAllChildren();
            bulletAppState.getPhysicsSpace().remove(node);
            //Main.lights.redoShadows();
        }
    }
}
